/*============================================================================*/
/*                   CONTINENTAL AUTOMOTIVE SYSTEMS                           */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* name:            HALPorts.c
* version:         1.1
* created_by:      Lizette Acosta/Rodrigo Casados
* date_created:    June 22 2013
*=============================================================================*/
/* DESCRIPTION : Initializes ports                                            */
/*============================================================================*/
/* FUNCTION COMMENT : Implements entry point (main function) and other        */
/* application stuff.                                                         */
/*                                                                            */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.1      | 22/June/2013 |                              | Lizette Acosta   */
/*                                                           Rodrigo Casados  */
/*============================================================================*/

#include "HALPorts.h"
void (*ptrToLedEnable[10])(void);


void Init_Peri(void)
{
	Init_Ports();
	Init_Btn();
	Init_LED();
	
	/* Initialize array of pointers tu functions */
	ptrToLedEnable[LED_1] = LED_1x;
	ptrToLedEnable[LED_2] = LED_2x;
	ptrToLedEnable[LED_3] = LED_3x;
	ptrToLedEnable[LED_4] = LED_4x;
	ptrToLedEnable[LED_5] = LED_5x;
	ptrToLedEnable[LED_6] = LED_6x;
	ptrToLedEnable[LED_7] = LED_7x;
	ptrToLedEnable[LED_8] = LED_8x;
	ptrToLedEnable[LED_9] = LED_9x;
	ptrToLedEnable[LED_10] = LED_10x;
}


void LED_1x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,0);
	IO_PinWrite(pin_PA4,0);
	IO_PinWrite(pin_PA6,0);
	IO_PinWrite(pin_PA8,0); 
	IO_PinWrite(pin_PA1,0);
	IO_PinWrite(pin_PA3,0);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_2x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,0);
	IO_PinWrite(pin_PA6,0);
	IO_PinWrite(pin_PA8,0); 
	IO_PinWrite(pin_PA1,0);
	IO_PinWrite(pin_PA3,0);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_3x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,0);
	IO_PinWrite(pin_PA8,0); 
	IO_PinWrite(pin_PA1,0);
	IO_PinWrite(pin_PA3,0);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_4x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,0); 
	IO_PinWrite(pin_PA1,0);
	IO_PinWrite(pin_PA3,0);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_5x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,1); 
	IO_PinWrite(pin_PA1,0);
	IO_PinWrite(pin_PA3,0);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_6x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,1); 
	IO_PinWrite(pin_PA1,1);
	IO_PinWrite(pin_PA3,0);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_7x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,1); 
	IO_PinWrite(pin_PA1,1);
	IO_PinWrite(pin_PA3,1);
	IO_PinWrite(pin_PA5,0);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_8x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,1); 
	IO_PinWrite(pin_PA1,1);
	IO_PinWrite(pin_PA3,1);
	IO_PinWrite(pin_PA5,1);
	IO_PinWrite(pin_PA7,0);
	IO_PinWrite(pin_PA9,0);
}

void LED_9x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,1); 
	IO_PinWrite(pin_PA1,1);
	IO_PinWrite(pin_PA3,1);
	IO_PinWrite(pin_PA5,1);
	IO_PinWrite(pin_PA7,1);
	IO_PinWrite(pin_PA9,0);
}

void LED_10x(void)
{
	IO_PinWrite(pin_PA0,1); 
	IO_PinWrite(pin_PA2,1);
	IO_PinWrite(pin_PA4,1);
	IO_PinWrite(pin_PA6,1);
	IO_PinWrite(pin_PA8,1); 
	IO_PinWrite(pin_PA1,1);
	IO_PinWrite(pin_PA3,1);
	IO_PinWrite(pin_PA5,1);
	IO_PinWrite(pin_PA7,1);
	IO_PinWrite(pin_PA9,1);
}
